<template>
  <div class="page">
    <van-cell-group>
      <van-field   type="password" v-model="params.oldpasswd" placeholder="请输旧密码" />
      <van-field   type="password" v-model="params.passwd" placeholder="请输入新密码" />
      <van-field   type="password" v-model="params.passwd1" placeholder="请确认密码" />
    </van-cell-group>
    <div class="loginItem" :class="{active:btnstatu}" @click="changepsd">修改密码</div>
  </div>
</template>

<script type="text/ecmascript-6">
import { changePsd } from "../../api/user";

import utils from "../../assets/js/util";
import { objFull } from "../../assets/js/tools";
export default {
  name: "changepsd",

  data() {
    return {
      params: {
        passwd: "", //输入密码
        passwd1: "",
        oldpasswd: ""
      },
      isClick: false //防止多次点击验证码
    };
  },
  computed: {
    btnstatu() {
      if (objFull(this.params)) {
        return true;
      } else {
        return false;
      }
    }
  },
  methods: {
    changepsd() {
      if (!this.params.oldpasswd) {
        this.$toast("旧密码不可以为空");
        return;
      }
      if (!this.params.passwd) {
        this.$toast("新密码不可以为空");
        return;
      }
      if (this.params.passwd !== this.params.passwd1) {
        this.$toast("两次输入密码不一致");
        return;
      }
      if (this.isClick) {
        return;
      }
      this.isClick = true;

      changePsd(this.params).then(res => {
        this.isClick = false;
        if (res.code == "0000") {
          this.$toast("密码修改成功,请重新登陆");
          this.$router.push({ path: "person" });
        } else {
          this.$toast(res.msg);
        }
      });
    }
  }
};
</script>

<style scoped lang="less">
.page {
  height: 100%;
  background: #ffffff;
}
.van-cell {
  padding: 15px;
}

.loginItem {
  width: 6.3rem;
  height: 1rem;
  line-height: 1rem;
  text-align: center;
  margin: 1rem auto 0.3rem;
  background: rgba(242, 243, 245, 1);
  border-radius: 0.08rem;
  color: rgba(131, 134, 133, 1);
  &.active {
    background: rgba(228, 152, 41, 1);
    color: #ffffff;
  }
}
.loginM-register {
  height: 1.1rem;
  line-height: 1.1rem;
  text-align: center;
  color: rgba(131, 134, 133, 1);
  .a {
    color: rgba(228, 152, 41, 1);
  }
}
</style>
